// 打开地址:https://space.bilibili.com/{uid}/dynamic
// {uid}替换uid
let periodMin = 800//点赞间隔，单位毫秒
let periodMax = 2000//点赞间隔，单位毫秒
let batchPeriod = 2500//每批次点赞间隔，单位毫秒 每批动态点赞结束后将滚动条拉到最下加载动态的间隔（网卡的话设置长一点）
let deleteEl = true // 是否删除已经点赞过的动态 true:是
function sleep(ms){
    return new Promise(resolve => setTimeout(resolve, ms));
}
function getRandomInt(min, max) {
    min = Math.ceil(min)
    max = Math.floor(max)
    return Math.floor(Math.random() * (max - min + 1)) + min
}
function getBtnList(){
    let res = []
    let list = document.getElementsByClassName('bili-dyn-action like')
    list.forEach(e=>{
        if (!e.classList.contains('active')) {
            res.push(e)
        }else{
            removeElement(e)
        }
    })
    return res
}
async function doClick(list){
    for (let i = 0; i < list.length; i++) {
        list[i].click()
        console.log('已点赞一条动态')
        await sleep(getRandomInt(periodMin,periodMax))
        removeElement(list[i])
    }
}
function removeElement(e){
    if(!deleteEl){
        return
    }
    let boxList = document.getElementsByClassName('bili-dyn-list__item')
    for(let i = 0;i < boxList.length;i++){
        if(boxList[i].contains(e)){
            boxList[i].remove()
        }
    }
}
async function clickAndScroll(){
    let list = getBtnList()
    await doClick(list)
    console.log('本批次结束 数量'+list.length)
    window.scrollTo({
      top: 0,
      behavior: "smooth"
    })
    await sleep(900)
    window.scrollTo({
        top: document.documentElement.scrollHeight,
        behavior: 'smooth'
    });
    await sleep(batchPeriod)
    return getBtnList().length
}
(async function main(){
    do {
        await clickAndScroll()
    }while(document.getElementsByClassName('bili-dyn-list-no-more').length === 0 || getBtnList().length > 0)
})()